/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classes;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rad.Java.Common.Class.DefaultList;
import rad.Java.Common.Class.IList;
import rad.Java.Common.DB.GenerateSql;
/**
 *
 * @author rogerio
 */
public class Estabelecimentos extends DefaultList implements IList {

    private estabelecimento c;

    public Estabelecimentos()//Constructor
    {
        c = new estabelecimento();
        _gsql = new GenerateSql();
        _gsql.setTable("estabelecimentos");
    }

    public estabelecimento get(int index)
    {
        return(estabelecimento) _items.get(index);
    }

    public boolean fillList()
    {
        _gsql.prepare();
        _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
        _gsql.setValue("","*");
        _gsql.setConditionalWhere("enable = 'true'");
        try {
            return mountList();
        } catch (SQLException ex) {
            Logger.getLogger(Estabelecimentos.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    public boolean fillList(String sql) throws SQLException
    {
        _gsql.prepare();
        _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
        _gsql.setValue("","*");
        _gsql.setConditionalWhere(sql);
        _gsql.setConditionalWhere("enable = 'true'");
        return mountList();
    }

    private boolean mountList() throws SQLException
    {
        ResultSet rs;
        if (!_gsql.execute(false))
            return false;
        clear();
        
        while(_gsql.next())
        {
            estabelecimento e = new estabelecimento();
            e.get(_gsql.getResultSet());
            _items.add(e);
        }
        return true;
    }
}

